#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>

int g_unval;
int g_val=100;
int main(int argc, char* argv[], char* env[])
{
    printf("code addr: %p\n", main);         //打印函数地址
    printf("init data addr: %p\n",&g_val);
    printf("uninit data addr: %p\n",&g_unval);

    char *heap = (char*)malloc(20);
    char *heap1 = (char*)malloc(20);
    char *heap2 = (char*)malloc(20);
    char *heap3 = (char*)malloc(20);

    printf("heap addr: %p\n",heap);        //heap是在堆区上开的那段空间的首地址 
    printf("heap1 addr: %p\n",heap1);         
    printf("heap2 addr: %p\n",heap2);         
    printf("heap3 addr: %p\n",heap3);         

    
    printf("stack addr: %p\n",&heap);         
    printf("stack addr: %p\n",&heap1);         
    printf("stack addr: %p\n",&heap2);         
    printf("stack addr: %p\n",&heap3);


    printf("命令行参数 表的地址\n");
    for(int i=0;argv[i];i++)
    {
        printf("&argv[%d]=%p\n", i, argv+i);
    }
    printf("环境变量 表的地址\n");
    for(int i=0;env[i];i++)
    {
        printf("&env[%d]=%p\n",i,env+i);
    }

    printf("命令行参数 表内容的地址\n");
    for(int i=0;argv[i];i++)
    {
        printf("argv[%d]=%p\n", i, argv[i]);
    }
    printf("环境变量 表内容的地址\n");
    for(int i=0;env[i];i++)
    {
        printf("env[%d]=%p\n",i,env[i]);
    }
    /*  
    code addr: 0x4005bd               
    init data addr: 0x601044
    uninit data addr: 0x60104c
    heap addr: 0xf51010
    heap1 addr: 0xf51030
    heap2 addr: 0xf51050
    heap3 addr: 0xf51070
    stack addr: 0x7fff3b165ce8
    stack addr: 0x7fff3b165ce0
    stack addr: 0x7fff3b165cd8
    stack addr: 0x7fff3b165cd0
    命令行参数 表的地址
    &argv[0]=0x7fff3b165de8
    环境变量 表的地址
    &env[0]=0x7fff3b165df8
    &env[1]=0x7fff3b165e00
    &env[2]=0x7fff3b165e08
    &env[3]=0x7fff3b165e10
    &env[4]=0x7fff3b165e18
    &env[5]=0x7fff3b165e20
    &env[6]=0x7fff3b165e28
    &env[7]=0x7fff3b165e30
    &env[8]=0x7fff3b165e38
    &env[9]=0x7fff3b165e40
    &env[10]=0x7fff3b165e48
    &env[11]=0x7fff3b165e50
    &env[12]=0x7fff3b165e58
    &env[13]=0x7fff3b165e60
    &env[14]=0x7fff3b165e68
    &env[15]=0x7fff3b165e70
    &env[16]=0x7fff3b165e78
    &env[17]=0x7fff3b165e80
    &env[18]=0x7fff3b165e88
    &env[19]=0x7fff3b165e90
    &env[20]=0x7fff3b165e98
    &env[21]=0x7fff3b165ea0
    &env[22]=0x7fff3b165ea8
    命令行参数 表内容的地址
    argv[0]=0x7fff3b1667e0
    环境变量 表内容的地址
    env[0]=0x7fff3b1667e9
    env[1]=0x7fff3b1667fe
    env[2]=0x7fff3b16681f
    env[3]=0x7fff3b16682a
    env[4]=0x7fff3b16683a
    env[5]=0x7fff3b166848
    env[6]=0x7fff3b16686a
    env[7]=0x7fff3b166890
    env[8]=0x7fff3b1668a3
    env[9]=0x7fff3b1668ab
    env[10]=0x7fff3b1668ed
    env[11]=0x7fff3b166e89
    env[12]=0x7fff3b166ea1
    env[13]=0x7fff3b166ef9
    env[14]=0x7fff3b166f25
    env[15]=0x7fff3b166f36
    env[16]=0x7fff3b166f4d
    env[17]=0x7fff3b166f55
    env[18]=0x7fff3b166f63
    env[19]=0x7fff3b166f6e
    env[20]=0x7fff3b166fa2
    env[21]=0x7fff3b166fc5
    env[22]=0x7fff3b166fe4

     
     */
    return 0;
}


//int main()
//{
//    const char *myenv=getenv("hello");
//    if(myenv==NULL) printf("没有找到\n");
//    else printf("myenv = %s\n",myenv);
//    return 0;
//}
//
//










//
//int main()
//{
//
//    extern char** environ;
//    // envior
//   for(int i=0; environ[i]; i++)
//   {
//        printf("environ[%d]: %s\n", i, environ);
//   }
//    return 0;
//}
//
//

//int main()
//{
//    const char* username = getenv("USER");
//    if(strcmp(username, "qz")==0 || strcmp(username, "qianzhuo")==0){
//        printf("this is my process core function\n");
//    }
//    else{
//        printf("你没有权限\n");
//    }
//    return 0;
//}
//
//
